{include file='public/head2'}
<div id="main-page">
    <div class="wap">
        <div class="container bg-white">
            <div class="search-bar">
                <form class="search-bar__form" id="searchBar">
                    <div class="form-input-block">
                        <input type="search" class="iconfont form-input" id="title" placeholder="&#xe644; 搜索活动" value="{$_GPC['title']}">
                    </div>
                    <input type="hidden" name="paytype" id="paytype" value="{$_GPC['paytype']}">
                    <input type="hidden" name="status" id="status" value="{$_GPC['status']}">
                </form>
            </div>
            <div class="navbar">
                <div class="navbar__item" onclick="$('#nav-type').fadeToggle('fast')">
                    {if !isset($_GPC['paytype']) || $_GPC['paytype']==''}全部类型{/if}
                    {if isset($_GPC['paytype']) && $_GPC['paytype']=='0'}卡券模式{/if}
                    {if isset($_GPC['paytype']) && $_GPC['paytype']=='1'}纯推广模式{/if}
                    <span class="iconfont iconxia"></span>
                    <ul class="dropdown-menu" id="nav-type">
                        <li><a class="menu-paytype" data-val="" href="javascript:;">全部类型</a></li>
                        <li><a class="menu-paytype" data-val="0" href="javascript:;">卡券模式</a></li>
                        <li><a class="menu-paytype" data-val="1" href="javascript:;">纯推广模式</a></li>
                    </ul>
                </div>
                <div class="navbar__item" onclick="$('#nav-status').fadeToggle('fast')">
                    {if $_GPC['status']=='1'}进行中{/if}
                    {if $_GPC['status']=='0'}已结束{/if}
                    <span class="iconfont iconxia"></span>
                    <ul class="dropdown-menu" id="nav-status">
                        <li><a class="menu-status" data-val="1" href="javascript:;">进行中</a></li>
                        <li><a class="menu-status" data-val="0" href="javascript:;">已结束</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="container p-3">
            <div class="container data-box" style="padding-bottom:1rem;">
                {foreach $list as $item}
                <div class="salebox bg-white br-10 mb-3">
                    <div class="box mb-3">
                        <a href="{$_W['baseurl']}/index/sale/tuiguangqr?id={$item['id']}" class="sale-pic">
                            <span class="iconfont iconsaoma"></span>
                        </a>
                        <div class="sale-title">
                            <a class="ajax" href="{$_W['baseurl']}/index/member/sale?id={$item['id']}">{$item['title']}</a>
                            <div class="mt-1">
                                {if $item['paytype']==0}<div class="badge badge-red">卡券模式</div>{/if}
                                {if $item['paytype']==1}<div class="badge badge-blue">纯推广模式</div>{/if}
                                {if $item['endtime']+86400<$_W['timestamp']}
                                <span class="fc-light ml-3">已结束</span>
                                {else}
                                <span class="fc-green ml-3">进行中</span>
                                {/if}
                            </div>
                        </div>
                    </div>
                    <div class="box">
                        <div class="row">
                            <div class="col-3 tac sale-tongji">
                                <p>{$item['view']}</p>
                                <p>已扫次数</p>
                                <div class="line"></div>
                            </div>
                            <div class="col-3 tac sale-tongji">
                                <p>{$item['number']}</p>
                                <p>扫码次数</p>
                                <div class="line"></div>
                            </div>
                            <div class="col-3 tac sale-tongji">
                                <p>{:date("Y/m/d",$item['starttime'])}</p>
                                <p>开始时间</p>
                                <div class="line"></div>
                            </div>
                            <div class="col-3 tac sale-tongji">
                                <p>{:date("Y/m/d",$item['endtime'])}</p>
                                <p>结束时间</p>
                            </div>
                        </div>
                    </div>
                    <div class="box mt-3">
                        <div class="row">
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/salem/cards?id={$item['id']}" class="ajax btn btn-block">领券记录</a>
                            </div>
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/salem/users?id={$item['id']}" class="ajax btn btn-block">参与用户</a>
                            </div>
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/merch/editsale?id={$item['id']}" class="ajax btn btn-block">编辑活动</a>
                            </div>
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/merch/createvideo?id={$item['id']}" class="ajax btn btn-block">生成视频</a>
                            </div>
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/sale/tuiguang?id={$item['id']}" class="btn btn-block">活动海报</a>
                            </div>
                            {if $item['paytype']==0}
                            <div class="col-4 mb-2">
                                <a href="{$_W['baseurl']}/index/salem/verifyer?id={$item['id']}" class="ajax btn btn-block">核销员管理</a>
                            </div>
                            {/if}
                        </div>
                    </div>
                </div>
                {/foreach}
            </div>
        </div>
    </div>
    <div class="nav" id="nav">
        <div class="p-2">
            {if $_W['sysset']['agent_level']==''}
            <a href="{$_W['baseurl']}/index/merch/createsale" class="btn btn-block btn-default">创建活动</a>
            {else}
            <div class="row">
                <div class="col-6">
                    <a href="{$_W['baseurl']}/index/merch/recharge" class="btn btn-block btn-default">充值次数</a>
                </div>
                <div class="col-6">
                    <a href="{$_W['baseurl']}/index/merch/createsale" class="btn btn-block btn-default">创建活动</a>
                </div>
            </div>
            {/if}
        </div>
    </div>
    <script>
        $(function(){
            var page = {$page};
            var limit = {$limit};
            var count = {$count};
            var totalheight = $(document).height()-50;//定义一个总的高度变量
            
            $(window).scroll(function () {
                if(count<limit*page){
                    return false;
                }
                totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());//浏览器的高度加上滚动条的高度 
                if ($(document).height() <= totalheight){ //当文档的高度小于或者等于总的高度的时候，开始动态加载数据
                    page++;
                    $.get("{$_W['baseurl']}&r=merch&page="+page+'&limit='+limit, function(res){
                        var data = $(res).find('.data-box').html();
                        $('.data-box').append(data);
                    });
                }
            });
            $('#searchBar').submit(function(){
                search();
                return false;
            });
            $('.menu-paytype').on('click', function(){
                $('#paytype').val($(this).data('val'));
                search();
            });
            $('.menu-status').on('click', function(){
                $('#status').val($(this).data('val'));
                search();
            });
            function search() {
                var url = '{$_W["baseurl"]}/index/merch?title='+$('#title').val()+'&paytype='+$('#paytype').val()+'&status='+$('#status').val();
                window.location.href = url;
            }
        });
    </script>
</div>
{include file='public/footer'}